﻿<%@ Page Title="" Language="C#" MasterPageFile="~/admin/Admin.master" AutoEventWireup="true" CodeFile="Language.aspx.cs" Inherits="admin_Language" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<script type="text/javascript" defer="defer" >
    $(document).ready(function() {
        var validated = $("#ctl00_ContentPlaceHolder1_tb_short").val() == '';
        $('#ctl00_ContentPlaceHolder1_tbName').blur( function () {
            if($(this).val() == "")
            {
                validated = false;
                $('#ctl00_ContentPlaceHolder1_tbName-exists').remove();
                $('#ctl00_ContentPlaceHolder1_tbName').after('<label id="ctl00_ContentPlaceHolder1_tbName-exists" for="ctl00_ContentPlaceHolder1_tbName" generated="true" class="error" style="display: inline;">Language name is required</label>');
            }
            else{
                $('#ctl00_ContentPlaceHolder1_tbName-exists').remove();
                validated = true;
             }
        });
        var rowNum = 1;
        var page = 1;
        var prevRowNum = 0;
        var sidx = "id";
        var sord = "Asc";
        var letter = "";
        var imgfilepath = '../components/jqGrid/themes/basic/images'; //define the path for the images
        jQuery("#listsg11").jqGrid({
            //url: 'webservice/Language.asmx?LoadAll',  //define the web service when the grid is loading
            type: "POST",
            dataType: "xml",
            datatype: function() {
                page = $("#listsg11").getGridParam("page");
                rowNum = $("#listsg11").getGridParam("rowNum");
                sidx = $("#listsg11").getGridParam("sortname");
                sord = $("#listsg11").getGridParam("sortorder");
                letter = $("#listsg11").getGridParam("url");
                if(letter==null) letter = "";
                if (rowNum != prevRowNum) {
                    prevRowNum = rowNum;
                    page = 1;
                }
                $("#listsg11").clearGridData();
                $.ajax({
                    url: "webservice/Language.asmx/LoadAll",
                
                    data: "page=" + page + "&pageSize=" + rowNum + "&sidx=" + sidx + "&sord=" + sord + "&letter="+letter,
                    //'{"page": ' + page + ', "pageSize": ' + rowNum + ', "sidx": "' + sidx + '", "sord":"'+sord+'"}',  // For empty input data use "{}",
                    dataType: "xml",
                    type: "POST",
                    //contentType: "application/text; charset=utf-8",
                    complete: function(xmlresponse, stat) {
                        if (stat == "success") {
                            var listsg11 = jQuery("#listsg11")[0];
                            listsg11.addXmlData(xmlresponse.responseXML);
                        }
                        var ids = $("#listsg11").getDataIDs();
                        for (var i = 0; i < ids.length; i++) {
                            var rowId = ids[i];
                            var rowData = $("#listsg11").getRowData(rowId);
                            fileLink = "<a  id='" + rowId + "' class='href_track bold' href='#'>" + rowData["LanguageName"] + "</a>"; //here we define which row data
                            $("#listsg11").setRowData(rowId, { LanguageName: fileLink });
                            $("#listsg11 a").click(function(e)  //define the click function, setting the modal popup
                            {
                                itemId = this.id;
                                $('#formDiv').modal({ onShow: modalShow, onOpen: modalOpen, onClose: modalClose });
                                function modalShow(dialog)//function for seting size on the modal
                                {
                                    dialog.container.css({
                                        width: 620
                                    });
                                }
                                function modalOpen(dialog) {  //the function when the modal is opened
                                    dialog.overlay.fadeIn('fast', function() {
                                        dialog.container.fadeIn('fast', function() {
                                            dialog.data.hide().slideDown('fast');
                                            //////////////////////////////////////////////////////////

                                            //On Load Fill Form for Selected
                                            $("#submit").val("Change"); //set the name of the buttont to change
                                            $("#ctl00_ContentPlaceHolder1_cbActive").removeAttr('checked');
											$("#ctl00_ContentPlaceHolder1_tbName").val('');
                                            $.ajax
												({
													url:"webservice/Language.asmx/getLang",
													data:'{ id: "'+itemId+'" }',
													dataType: "json",
													contentType: "application/json; charset=utf-8",
                                                    type: "POST",
													complete:function(json1) {
													    var c = JSON.parse(json1.responseText);
													    var d = JSON.parse(c.d);
													    $("#_id").val(d._id);
													    $("#ctl00_ContentPlaceHolder1_tbName").val(d._language_name);
													    $("#ctl00_ContentPlaceHolder1_tb_short").val(d._language_short);
													    
													    if(d._isActive)
													        $("#ctl00_ContentPlaceHolder1_cbActive").attr('checked', true);
													}
												});

                                            //OnClick make update  for Selected
                                            jQuery("#submit").click(function()    //update function for the data 
                                            {
                                                if(validated)
                                                {
                                                    $.ajax
												    ({
													    url:"webservice/Language.asmx/updateLang",
													    data:'{ id: "'+$("#_id").val()+'", language_name: "'+$("#ctl00_ContentPlaceHolder1_tbName").val()+'" , isActive: "'+$("#ctl00_ContentPlaceHolder1_cbActive").attr('checked')+'", _short:"'+$("#ctl00_ContentPlaceHolder1_tb_short").val()+'"}',
													    dataType: "json",
													    contentType: "application/json; charset=utf-8",
                                                        type: "POST",
													    complete:function(json1) {
													        $.modal.close();
													        jQuery("#listsg11").trigger("reloadGrid");
													    }
												    });  
                                                }
                                            });
                                            //////////////////////////////////////////////////////////
                                        });
                                    });
                                }

                                function modalClose(dialog) {
                                    dialog.data.fadeOut('fast', function() {
                                        dialog.container.hide('fast', function() {
                                            dialog.overlay.slideUp('fast', function() {
                                                itemId = null;
                                                $.modal.close();
                                                jQuery("#listsg11").trigger("reloadGrid");
                                            });
                                        });
                                    });
                                }

                            });
                        }
                    }
                });
            },
            height: 350,
            width: 1000,
            colNames: ['ID', 'Language Name', 'Short', 'Active'],    //here we define the colums of the grid
            colModel: [   //define the column properties
							   {name: 'ID', index: 'ID', width: 35, sorttype: 'int' },
							   {name: 'LanguageName', index: 'language_name', width: 350, sortable: true, sorttype: 'text' },
							   {name: 'short', index: 'short', width: 100, sorttype: 'text' },
							   {name: 'Active', index: 'isActive', width: 350, sortable: true, sorttype: 'text' },
						   ],                                 // end define the column properties
            rowNum: 30,
            rowList: [8, 10, 20, 30, 100],
            imgpath: imgfilepath,
            pager: jQuery('#pagersg11'), //set a name for the pager, the navigation bar
            sortname: 'ID',  //define the default sorting column
            viewrecords: true,
            sortorder: "asc",   //define the default sorting direction
            caption: "Languages",      //define the Caption
            multiselect: true,
            subGrid: false,
        })
					.navGrid('#pagersg11', { refresh: false, add: false, edit: false, del: false, search: false })
					.navButtonAdd('#pagersg11', { caption: "Add New", onClickButton: function()//define a button in the navigation bar for creating new data
					{
					    //Attach Modal Form for Insert New Record
					    $('#formDiv').modal({ onShow: modalShow, onOpen: modalOpen, onClose: modalClose }); //definig the modal popup
					    $("#submit").val("submit");
					    function modalShow(dialog)//define the size of the modal popup
					    {
					        dialog.container.css({
					            width: 620
					        });
					    }
					    function resetForm()    //reset the form
					    {
					        $("#ctl00_ContentPlaceHolder1_tbName").val("");
					        $("#ctl00_ContentPlaceHolder1_cbActive").removeAttr('checked');
					    }
					    function modalOpen(dialog) {
					        dialog.overlay.fadeIn('fast', function() {
					            dialog.container.fadeIn('fast', function() {
					                dialog.data.hide().slideDown('fast');
					                //////////////////////////////////////
					                //Reset form
					                resetForm();
					                // Attach Event handler for Inserting New Records
					                $("#submit").click(function() {
					                    if(validated)
                                        {
                                            $.ajax
										    ({
											    url:"webservice/Language.asmx/insLang",
											    data:'{language_name: "'+$("#ctl00_ContentPlaceHolder1_tbName").val()+'" , isActive: "'+$("#ctl00_ContentPlaceHolder1_cbActive").attr('checked')+'", _short:"'+$("#ctl00_ContentPlaceHolder1_tb_short").val()+'"}',
											    dataType: "json",
											    contentType: "application/json; charset=utf-8",
                                                type: "POST",
											    complete:function(json1) {
											        $.modal.close();
											        jQuery("#listsg11").trigger("reloadGrid");
											    }
										    });  
                                        }
					                });
					                //////////////////////////////////////
					            });
					        });
					    }


					    function modalClose(dialog) {
					        dialog.data.fadeOut('fast', function() {
					            dialog.container.hide('fast', function() {
					                dialog.overlay.slideUp('fast', function() {
					                    $.modal.close();
					                });
					            });
					        });
					    }

					}, position: "last"
					})
					.navGrid('#pagersg11', { refresh: true, add: false, edit: false, del: false, search: false })
					.navButtonAdd('#pagersg11', { caption: "Delete Selected", onClickButton: function() {
					    var s = jQuery("#listsg11").getGridParam("selarrrow");
					    if (s != "") {
					        //Send Ajax Request for Deleting Selected Records

					        /*$('#confirm').modal({
					            close: false,
					            overlayId: 'confirmModalOverlay',
					            containerId: 'confirmModalContainer',
					            onShow: function(dialog) {
					                // if the user clicks "yes"
					                jQuery("#btn_yes").click(function() {
					                    //Delete Selected rows
					                    $.ajax({
					                        type: "POST",
					                        url: '',
					                        data: "id=" + s,
					                        success: function(msg) {
					                            jQuery("#listsg11").trigger("reloadGrid");
					                        }
					                    });
					                    // close the dialog
					                    $.modal.close();
					                });
					            }
					        });*/
					    }
					    else {
					        alert("Please select records to delete.");
					    }
					}, position: "last"
	})
					<% for(int i=65;i<91;i++){
					    char s = (char)i; %>
							.navButtonAdd("#pagersg11", { caption: '<%=s %>', buttonimg: '',
							    onClickButton: function() {
							        var new_url = this.caption;
							        $("#listsg11").setGridParam({ url: new_url, page: 1 });
							        $("#listsg11").trigger("reloadGrid");
							    }, position: "last", title: '<%=s %>', reloadAfterSubmit: true
							})
					<%}%>
        //insert the All Records button
							.navButtonAdd("#pagersg11", { caption: 'All Records', buttonimg: '',
							    onClickButton: function() {
							        var new_url = '';
							        $("#listsg11").setGridParam({ url: new_url, page: 1 });
							        $("#listsg11").trigger("reloadGrid");
							    }, position: "last", title: 'All Records', reloadAfterSubmit: true
							})
							 ;

    });
					 </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<br />
<table id="listsg11" class="scroll" cellpadding="0" cellspacing="0"></table>
<div id="pagersg11" class="scroll" style="text-align:center;"></div>

<form id="formname" name="formname" action="">
    <div id="formDiv" style="display: none; width: 600px; background: #EEEEEE">
        <input id="_id" type="hidden" />
        <div id="wrapperLogInInside">
            <div id="UpWrapp">
                <h1 class="titleLoginInside">
                    Language</h1>
            </div>
            <div id="contentWrappLogin">
                <div class="contentLogin">
                    <div class="inputDiv">
                        <asp:Label ID="Label1" for="" class="tdLeftInside" runat="server" Text="language name"></asp:Label>
                        <asp:TextBox ID="tbName" class="searcxBoxNameInside valid" runat="server"></asp:TextBox>
                    </div>
                    <div class="inputDiv">
                        <asp:Label ID="Label3" for="" class="tdLeftInside" runat="server" Text="language short name"></asp:Label>
                        <asp:TextBox ID="tb_short" class="searcxBoxNameInside valid" MaxLength="5" runat="server"></asp:TextBox>
                    </div>
                    <div class="inputDiv">
                        <asp:Label ID="Label2" class="tdLeftInside" for="" runat="server" Text="Is Active"></asp:Label>
                        <asp:CheckBox ID="cbActive" class="valid" runat="server" />
                    </div>
                    <div class="inputDiv">
                        <input type="submit" class="buttonInside" value="submit" id="submit" name="submit" />
                    </div>
                </div>
            </div>
            <div id="FooterMenuWrappLogin">
            </div>
        </div>
    </div>
    </form>
<br />
</asp:Content>

